<?php
// 本类由系统自动生成，仅供测试用途
class PublicAction extends CommonAction{
	var $url = "__APP__"; 
	public function index() { 
		  echo "Access Denied!!";
	}
	
	public function reg(){
		
		if($_POST['reg_btn']){
			$meber['acc_name'] = $_POST['acc_name'];
			$meber['pwd'] =  MD5($_POST['pwd']);
			$meber['email'] =  $_POST['email'];
			$meber['province'] =  $_POST['province'];
			$meber['city'] =  $_POST['city'];
			
			if($_SESSION['verify'] != md5($_POST['verify'])){
				$msg="验证码错误！";
				$this->assign('jumpUrl',"__URL__/reg"); 
			}
			else{
				if(d("member_info")->add($meber)){
					Cookie::set('acc_name',$meber['acc_name']);
					$msg="注册成功！";
				}
				else{
					$msg="注册失败！";
				}
				$this->assign('jumpUrl',$this->url); 
			}
			$this->success($msg);
		}
		else{
			$this->display();
		}

	}

	public function login(){
		$this->display();
	}
	
	public function logout(){
		Cookie::delete('acc_name');
		setcookie ("acc_name","", time());
		$this->assign("jumpUrl","__APP__");
		$this->success("注销成功!");
	}
	
	public function checkuser(){
		//echo $_SESSION['verify']."<br>";
		//echo md5($_POST['verify'])."<br>";
		if($_SESSION['verify'] != md5($_POST['verify'])){
			//echo "3";
			$this->ajaxReturn(__ROOT__."/admin.php/public/verify/",'验证码错误',0);
		}
		elseif(!$_POST['acc_name']){
			$this->error('用户名不能为空！');
		}
		else{
			
			$map['acc_name'] = $_POST['acc_name'];
			$map['pwd'] = md5($_POST['pwd']);
			$user = D("member_info");
			$checkUser = $user->where($map)->find();
			
			if(!$checkUser){
				
				$this->ajaxReturn(__ROOT__."/admin.php/public/verify/","用户名或密码不正确！",0);
			}else{
				
				Cookie::set('acc_name',$map['acc_name']);
				$this->ajaxReturn(__ROOT__."/index.php","登录成功",1);				
			}

		}
	}
	
	function chk_acc(){
		$mid = $_POST['acc'];
		if(!empty($mid)){
			$map['acc_name'] = $mid;			
			$user = D("member_info");
			$checkUser = $user->where($map)->find();
			if($checkUser){
				echo "1";
			}
			else{
				echo "0";
			}			
		}
		else{
			echo "0";
		}
	}	
	
}
?>